package com.rt.gptnext.common.utils.http;

import cn.hutool.extra.spring.SpringUtil;
import com.rt.gptnext.common.utils.http.engine.OkhttpEngine;

/**
 * @author gaoyiyang
 **/
public class HttpEngineManager {

    public static HttpEngine getGlobalEngine() {
        try {
            HttpEngine engine = SpringUtil.getBean(HttpEngine.class);
            if (engine != null) {
                return engine;
            }
        } catch (Exception ignore) {

        }
        return newEngine();
    }

    public static HttpEngine newEngine() {
        return newEngine(false);
    }

    public static HttpEngine newEngine(boolean pool) {
        return newEngine(pool, 10, 60);
    }

    public static HttpEngine newEngine(boolean pool, int maxIdleConnections, int timeoutSeconds) {
        return new OkhttpEngine(pool, maxIdleConnections, timeoutSeconds);
    }

}
